import req from '@/utils/request.js';
import * as URL from '@/constants/api.js';

export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  })
    .then((res) => {
      const token = res.data.result.token;
      localStorage.setItem('TOKEN', `Bearer ${token}`);
      return res;
    })

    .catch((err) => Promise.reject(err.response.data));
}
export function loginWithCode(mobile) {
  return req({
    url: URL.LOGIN_CODE,
    params: {
      mobile,
    },
  })
    .then((res) => res.data.msg)
    .catch((err) => Promise.reject(err.response.data.message));
}
